// Copyright © 2023 Dean Lee import Error from 'next/error'; import ReactMarkdown from 'react-markdown'; import { IconContext } from 'react-icons'; import { GoFile, GoFileDirectory, GoGitCommit, GoGitBranch, GoTag } from 'react-icons/go'; import gfm from 'remark-gfm'; import hljs from 'highlight.js'; import path from 'path'; function getRawURL(pathArray) { return `/${pathArray[0]}/raw/${pathArray.slice(2).join('/')}`; } function getLanguage(filename) { switch (path.extname(filename)) { case '.java': return 'java'; case '.html': case '.xml': return 'xml'; case '.md': return 'md'; case '.c': case '.h': return 'c'; case '.tex': return 'tex'; case '.js': return 'js'; case '.fs': return 'fs'; case '.elm': return 'elm'; case '.json': return 'json'; case '.py': return 'py'; case '.css': return 'css'; default: return 'plaintext'; } } function isImage(filename) { switch (path.extname(filename)) { case '.gif': case '.jpeg': case '.jpg': case '.png': case '.tiff': case '.tif': return true; default: return false; } } function makeBreadCrumbObj(name, pathArray) { const breadCrumbObj = { name: name, href: `/${pathArray.join('/')}`, }; return breadCrumbObj; } async function getServerSideProps(context) { const res = await fetch(`http://localhost:3000/api${context.resolvedUrl}`); const data = await res.json(); if (data.resultType === 'notFound') { return { notFound: true }; } else { return { props: { data } }; } } function Button({ label, url }) { return ( {label} ); } function Link({ label, url }) { return ( {label} ); } function ListItemWithIcon({ icon, iconColor, name, url }) { return (
  • {icon}
    {name}
  • ); } function MainContentContainer({ children }) { return (
    {children}
    ); } function LineNos({ textBlob }) { const count = textBlob.split('\n').length; const lineNos = [...Array(count).keys()].map((x) => x + 1).join('\n'); return (
          {lineNos}
        
    ); } function CodeBlock({ textBlob, resultPath }) { const language = getLanguage(resultPath[resultPath.length - 1]); const highlightedHTML = hljs.highlight(textBlob, { language: language, ignoreIllegals: true }).value; return (
          
        
    ); } function TextDisplayGrid({ textBlob, resultPath }) { return (
    ); } function BreadCrumbTrail({ pathArray }) { const recursion = (acc) => { if (acc.length === pathArray.length - 4) { return acc; } else { const subArray = pathArray.slice(0, 1).concat('tree', pathArray.slice(2, acc.length + 4)); const breadCrumb = makeBreadCrumbObj(pathArray[acc.length + 3], subArray); const newAcc = acc.concat([breadCrumb]); return recursion(newAcc); } }; if (pathArray.length < 4) { return null; } let rootArray; if (pathArray[2] === 'master') { rootArray = pathArray.slice(0, 1); } else { rootArray = pathArray.slice(0, 1).concat('tree', pathArray[2]); } const headBreadCrumb = makeBreadCrumbObj(pathArray[0], rootArray); const tailBreadCrumbs = recursion([]); const breadCrumbs = [headBreadCrumb].concat(tailBreadCrumbs); return (
    {breadCrumbs.map((breadCrumb, index) => ( / ))} {pathArray[pathArray.length - 1]}
    ); } function ReadmeDisplay({ resultContent, resultPath }) { const imageURITransformer = (uri) => `/${resultPath[0]}/raw/master/${uri}`; const titleClasses = 'text-2xl text-slate-800 pb-4 border-b border-slate-300'; const articleClasses = 'pt-4 prose md:prose-xl prose-slate max-w-none prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline'; return (

    {resultContent.readmeName}

    ); } function TextBlobArea({ resultContent, resultPath }) { return (
    ); } function BinaryBlobArea({ resultPath }) { let binaryDisplay; if (isImage(resultPath[resultPath.length - 1])) { binaryDisplay = {'Embedded; } else { binaryDisplay =

    Binary content cannot be displayed.

    ; } return (
    {binaryDisplay}
    ); } function BranchesAndTagsLinks({ pathArray }) { const commit = pathArray.length > 2 ? pathArray[2] : 'master'; return (
    ); } function MidSection({ resultPath }) { const commit = resultPath.length > 2 ? resultPath[2] : 'master'; const commitClasses = 'text-xl md:text-2xl py-2 px-4 mr-4 md:mr-8 border border-slate-300 rounded-lg truncate'; let navigation; if (resultPath.length > 3) { navigation = ; } else { navigation = ; } return (
    {resultPath.length !== 2 && (
    {commit}
    )} {navigation}
    {resultPath.length === 1 && (
    {`git clone https://git.cleanslatesoftware.com/${resultPath[0]}`}
    )}
    ); } function DirectoryListing({ resultContent, resultPath }) { const makeURL = (repoRequest, item) => { const parentTail = resultPath.length > 2 ? resultPath.slice(2) : ['master']; const parentPath = resultPath.slice(0, 1).concat(repoRequest, parentTail); const url = `/${parentPath.join('/')}/${item}`; return url; } return (
      {resultContent.trees.map((item, index) => ( } iconColor={'text-blue-400'} name={item} url={makeURL('tree', item)} /> ))} {resultContent.blobs.map((item, index) => ( } iconColor={'text-slate-500'} name={item} url={makeURL('blob', item)} /> ))}
    ); } function CommitListing({ resultContent, resultPath }) { return (
      {resultContent.map((item, index) => ( } iconColor={'text-slate-500'} name={item.message} url={`/${resultPath[0]}/tree/${item.id}`} /> ))}
    ); } function BranchListing({ resultContent, resultPath }) { return (
      } iconColor={'text-slate-500'} name={'master'} url={`/${resultPath[0]}`} /> {resultContent.filter((x) => x !== 'master').map((item, index) => ( } iconColor={'text-slate-500'} name={item} url={`/${resultPath[0]}/tree/${item}`} /> ))}
    ); } function TagListing({ resultContent, resultPath }) { return ( {resultContent.length === 0 && (

    There are no tags in this project.

    )}
      {resultContent.reverse().map((item, index) => ( } iconColor={'text-slate-500'} name={item} url={`/${resultPath[0]}/tree/${item}`} /> ))}
    ); } function RepositoryListing({ repositories }) { return (
      {repositories.map((repo, index) => (
    • ))}
    ); } function PageSubstance({ data }) { switch (data.resultType) { case 'home': return ; break; case 'rootDirectory': return (
    {data.resultContent.readmeExists && ( )}
    ); break; case 'nonRootDirectory': return (
    ); break; case 'textBlob': return (
    ); break; case 'binaryBlob': return (
    ); break; case 'commits': return (
    ); break; case 'branches': return (
    ); break; case 'tags': return (
    ); break; } } function Header({ resultPath }) { return (
    cleanslatesoftware.com {resultPath.length > 0 && ( / )}
    ); } function Footer() { return (
    Email: dean@cleanslatesoftware.com
    Copyright © 2023 Dean Lee
    ); } function Main({ data }) { switch (data.resultType) { case 'home': case 'rootDirectory': case 'nonRootDirectory': case 'textBlob': case 'binaryBlob': case 'commits': case 'branches': case 'tags': return (
    ); break; default: return ; } } export { getServerSideProps }; export default Main;